package enums;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Record;

public enum WxuserRole {
	SEVISER( 1 , "运维公司" ),
	STAFF( 2 , "运维人员" ),
	COMPANY( 3 , "企业" ),
	MANGER( 4 , "监管" );

	private int value;
	private String title;

	WxuserRole(int value, String title) {
		this.value = value;
		this.title = title ;
	}

	public int getValue() {
		return value;
	}

	public void setValue(int value) {
		this.value = value;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public static WxuserRole getValueByTitle(Integer value) {
		for (WxuserRole curEnum : WxuserRole.values()) {
			if (Objects.equals(value, curEnum.getValue())) {
				return curEnum ;
			}
		}
		return null ;
	}

	public static List<Map<String, Object>> toList() {
		List<Map<String, Object>> list = new ArrayList<>();
		WxuserRole[] values = values();
		for (WxuserRole curEnum : values) {
			Map<String, Object> item = new HashMap<>();
			item.put("value", curEnum.getValue());
			item.put("title", curEnum.getTitle());
			list.add(item);
		}
		return list;
	}

	public static String getTitleByValue(int value) {
		WxuserRole[] values = values();
		for (WxuserRole curEnum : values) {
			if (curEnum.getValue() == value) {
				return curEnum.getTitle();
			}
		}
		return "--" ;
	}
	
	public static String getTitleByValue(Record record , String key) {
		if (null == record || StrKit.isBlank(key) || null == record.getInt(key)) {
			return null ;
		}
		return getTitleByValue(record.getInt(key));
	}
	
	public static int getSeviser() {
		return SEVISER.getValue();
	}

	public static int getStaff() {
		return STAFF.getValue();
	}

	public static int getCompany() {
		return COMPANY.getValue();
	}

	public static int getManger() {
		return MANGER.getValue();
	}

}